<?php
namespace app\base\controller;
use framework\base\Config;
use framework\ext\UploadFile;
/* *
 * 根类
 * */
class BaseController extends \framework\base\Controller{
	
    public function __construct(){
        define('APP_PATH', ROOT_PATH . 'app' . DIRECTORY_SEPARATOR);  //APP目录
        define('DATA_PATH', ROOT_PATH . 'data' . DIRECTORY_SEPARATOR); //缓存目录
        define('__PUBLIC__', substr(PUBLIC_URL, 0, -1));  //附件目录
        define('__ROOT__', substr(ROOT_URL, 0, -1)); //系统网址
        defined('__TPL__') or define('__TPL__', ROOT_URL .'themes');  //前台模板目录
        include_once(APP_PATH . 'base/lib/function.php');   //引入函数
        $appConfig = BASE_PATH.'app/'.APP_NAME.'/config.php';   //引入APP配置函数
        if(file_exists($appConfig)){
            config(APP_NAME,require($appConfig));
        }
    }

    //上传处理
    public function files($files,$config){
        if(empty($files)){
            return false;
        }
        $upload = new UploadFile();  //上传类
        $upload->maxSize = 1024 * 1024 * intval($config['UP_SIZE']); //大小
        $upload->allowExts = explode(',',$config['UP_EXTS']);  //允许上传的文件的类型
        $upload->savePath = $config['UP_FOLDER'].date('Ymd').'/';  //设置文件上传目录的路径
        $upload->saveRule = unique_str; //上传文件名
        if ($upload->upload()){ //取得成功上传的文件信息
            $result = $upload->getUploadFileInfo()[0];
            $str['error'] = 0;
            $str['url'] = ROOT_URL.$result['savepath'].$result['savename'];
        }else{
            $result = $upload->getErrorMsg();
            $str['error'] = 1;
            $str['message'] = $result;
        }
        return json_encode($str);
    }
}